#include <vector>
#include <algorithm>
#include <functional>
#include <iostream>

using namespace std;

class Solution {
public:
    int findTheDistanceValue(vector<int>& arr1, vector<int>& arr2, int d) {
        if (arr1.size() == 0 || arr2.size() == 0) {
            return 0;
        }
        sort(arr2.begin(), arr2.end());
        int ans = 0;
        for (int i = 0; i < arr1.size(); i++) {
            vector<int>::iterator num1 = lower_bound(arr2.begin(), arr2.end(), arr1[i]);
            if (num1 == arr2.end()) {
                if (abs(arr1[i] - arr2.back()) > d) {
                    ans++;
                }
                continue;
            }
            if (num1 == arr2.begin()) {
                if (abs(arr1[i] - *num1) > d) {
                    ans++;
                }
                continue;
            }
            vector<int>::iterator num2 = num1 - 1;
            if (abs(arr1[i] - *num1) > d && abs(arr1[i] - *num2) > d) {
                ans++;
            }
        }
        return ans;
    }
};

int main() {
    vector<int> input1 = {-3,-3,4,-1,-10};
    vector<int> input2 = {7,10};
    Solution solution;
    int output = solution.findTheDistanceValue(input1, input2, 12);
    cout << output << endl;
    return 0;
}